const app = getApp()
Page({
  data: {
    avatar: '', // 头像
    nickName: '', // 昵称
  },
  onLoad() {
    app.token && this.getUserInfo()
  },
  async getUserInfo() {
    const {
      code,
      data: { avatar, nickName },
    } = await wx.http.get('/userInfo')
    if (code !== 10000) return wx.utils.toast()
    this.setData({
      avatar,
      nickName,
    })
    // 昵称和头像存储到全局实例中
    app.userProfile = {
      avatar,
      nickName,
    }
  },
})
